'use strict';

const random = function () {
  var storage = (function (length = 10) {
    const data =
      ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F",
        "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
        "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
        "s", "t", "u", "v", "w", "x", "y", "z"];
    let nums = "";
    for (let i = 0; i < length; i++) {
      const r = Math.floor(Math.random() * 61);
      nums += data[r];
    }
    return 'c2c_小菌_'+nums;
  })();
  console.log(storage);
  return storage;
}
module.exports = app => {
  const {ENUM, STRING, INTEGER, DATE } = app.Sequelize;

  const User = app.model.define('user', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    nick_name: {
      type: STRING(255),
      allowNull: true,
      comment: '昵称',
      defaultValue: random(),
    },
    photo: {
      type: STRING(255),
      allowNull: true,
      comment: '用户头像',
    },
    mobile: {
      type: STRING(255),
      allowNull: true,
      comment: '手机号',
    },
    sex:{
      type: ENUM(['男', '女']),
      allowNull: true,
      comment: '性别',
    },
    sign:{
      type: STRING(255),
      allowNull: true,
      comment: '个性签名',
    },
    address:{
      type: STRING(255),
      allowNull: true,
      comment: '地址',
    },
    created_at: DATE,
    updated_at: DATE,
  }, {
    sequelize:app.Sequelize,
    modelName: 'user',
    tableName: 'user',
    freezeTableName: true
  });

  return User;
};